<?php
namespace Core;

use Throwable;

/**
 * 公用异常类封装
 * Class Exception
 * @package Core
 */
class Exception extends \Exception
{
    protected $data = [];

    protected $debugMsg = '';

    /**
     * Exception constructor.
     * @param int $code
     * @param string $msg
     * @param array $data
     * @param string $debugMsg
     * @param Throwable|null $previous
     */
    function __construct($code = 0, $msg = "", $data = [], $debugMsg = '', Throwable $previous = null)
    {
        if(!empty($data)){
            $this->data = $data;
        }
        if( $debugMsg !== ''){
            $this->debugMsg = $debugMsg;
        }
        parent::__construct($msg, $code, $previous);
    }



    /**
     * 获取data
     * @return array
     */
    public function getData()
    {
        return !empty($this->data) ? $this->data : [];
    }

    /**
     * 获取错误提示
     * @return string
     */
    public function getDebugMsg()
    {
        return !empty($this->debugMsg) ? $this->debugMsg : '';
    }
}